import csv
from django.http import HttpResponse
from .models import PrettyNum


def text_csv(request):
    response = HttpResponse(content_type='text/csv')
    response['Content-Disposition'] = 'attachment;filename=mynum.csv'
    num = PrettyNum.objects.all()
    writer = csv.writer(response)
    writer.writerow(['mobile', 'price', 'level', 'status'])
    for i in num:
        writer.writerow([i.mobile, i.price, i.level, i.status])
    return response
